//
//  MyMovieViewController.m
//  newDouban
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MyMovieViewController.h"
#import "SingleTon.h"
#import "AllMovieDetailViewController.h"
@interface MyMovieViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableV;


@end

@implementation MyMovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"我的电影";
    self.tableV = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    //self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableV registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    
    [self.view addSubview:self.tableV];
    [_tableV release];
    
    
    if (!(self.myTitle == nil)) {
        
        [[SingleTon shareArray].movieArrary addObject:self.movieDetail];
        [[SingleTon shareArray].movieIDarray addObject:self.movieID];
    }
    [self.tableV reloadData];
    
   // NSLog(@"self.movieID%@", self.movieID);
    
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(leftButtion:)] autorelease];
    
}

- (void)leftButtion:(UIBarButtonItem *)sender
{
    UIViewController *VC = [self.navigationController.viewControllers  objectAtIndex:0];
    
    [self.navigationController popToViewController:VC animated:YES];
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //选中时候有置灰效果,离开时消失选中效果
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    AllMovieDetailViewController *allMovieDTVC = [[AllMovieDetailViewController alloc] init];
    //Movie *movie = [self.movieArray objectAtIndex:indexPath.row];
    NSString *movieID = [[SingleTon shareArray].movieIDarray objectAtIndex:indexPath.row];
    //NSLog(@"aaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbccccccccccccc%@", movieID);
    allMovieDTVC.movieID = movieID;
    [self.navigationController pushViewController:allMovieDTVC animated:YES];
    [allMovieDTVC release];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [SingleTon shareArray].movieArrary.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    UITableViewCell *cell = [[MovieListTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    
    static NSString *cellIndentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    
    
    MovieDetail *movieDetail = [[SingleTon shareArray].movieArrary objectAtIndex:indexPath.row];
    cell.textLabel.text = movieDetail.title;
    
    return cell;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
